package com.cershy.linyuminiserver.constant;

public enum DeviceType {
    // 为每个枚举常量添加对应的数字值
    CAMERA(1, "摄像头"),
    AUDIO_SYSTEM(2, "音响"),
    LIGHT(3, "灯光"),
    SENSOR(4, "传感器"),
    DISPLAY(5, "显示器"),
    PRINTER(6, "打印机");

    // 存储对应的数字值
    private final int code;
    // 存储设备类型的描述信息
    private final String description;

    // 构造方法，用于初始化枚举常量的数字值和描述信息
    DeviceType(int code, String description) {
        this.code = code;
        this.description = description;
    }

    // 获取枚举常量对应的数字值
    public int getCode() {
        return code;
    }

    // 获取枚举常量的描述信息
    public String getDescription() {
        return description;
    }

    // 根据数字值查找对应的枚举常量
    public static DeviceType fromCode(int code) {
        for (DeviceType type : values()) {
            if (type.getCode() == code) {
                return type;
            }
        }
        throw new IllegalArgumentException("No matching DeviceType for code: " + code);
    }
}
